package edu.je.column.util;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * @author MengXin
 * @description:
 * @program: je-gateway
 * @date 2021/4/21 21:27
 * @mail mx@radish.cloud
 */
public class PageUtil {
    public static final int DEFAULT_PAGE = 0;
    public static final int DEFAULT_PAGE_SIZE = 20;

    public static Pageable getPageable(Integer page, Integer size) {
        int p = page == null ? DEFAULT_PAGE : page;
        int s = size == null ? DEFAULT_PAGE_SIZE : size;
        return PageRequest.of(p, s);
    }

    public static Pageable getPageable(Integer page, Integer size, Sort sort) {
        int p = page == null ? DEFAULT_PAGE : page;
        int s = size == null ? DEFAULT_PAGE_SIZE : size;
        return PageRequest.of(p, s, sort);
    }

    public static void main(String[] args) {

    }
}
